from PIL import Image
img_1 = Image.open("2.jpg")
img_2 = Image.open("2_3.jpg")
pixels_1 = img_1.load()
w, h = img_1.size
for x in range(w):
    for y in range(h):
        r, g, b = pixels_1[x, y]
        pixels_2 = img_2.load()
        k = (r+g+b)/3
        if g > k * 1.4:
            pixels_1[x, y] = pixels_2[x, y]
img_1.show()
img_1.save("z_out.jpg", "JPEG")